/*! Bit.h */

#pragma once
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

class Bit
{
public:
	/*! Empty constructor */
	Bit(void) {}
	/*! Empty destructor */
	~Bit(void) {}

	/*! Returns '1' if a and b are equal to '1'*/
	char and(char a, char b)
	{
		if( a == '1' && b == '1')
			return '1';
		else
			return '0';
	}
	
	/*! Returns '1' if a or b are equal to '1'*/
	char or(char a, char b)
	{
		if(a == '1' || b == '1')
			return '1';
		else
			return '0';
	}
	
	/*! Returns '1' if a and b are different*/
	char xor(char a, char b)
	{
		if(a == '1' && b != '1' || b == '1' && a != '1')
			return '1';
		else
			return '0';
	}

	/*! Inverts the value '1' to '0' and '0' to '1'*/
	char not(char a)
	{
		if (a == 1)
			return '0';
		else
			return '1';
	}

	/*! Returns '1' if a and b are not equal to '1'*/
	char nand(char a, char b)
	{
		if (!(a == '1' && b == '1'))
			return '1';
		else
			return '0';
	}

	/*! Returns '1' if a or b are not equal to '1'*/
	char nor(char a, char b)
	{
		if (!(a == '1' || b == '1'))
			return '1';
		else
			return '0';
	}

	/*! Adds two bits, a and b, with ci as in-carry and cu as out-carry */
	void add(char a, char b, char ci, char &sum, char &cu)
	{
		char n1 = xor(a, b);
		char n2 = or(a, b);
		char n3 = and(ci, n2);
		char n4 = and(a, b);
		cu = or(n3, n4);
		sum = xor(n1, ci);
	}

};